package com.pesking.core.sqlparser.processor;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

import com.pesking.core.parameter.Parameter;
import com.pesking.core.sqlparser.parameter.SqlParameter;
import com.pesking.core.sqlparser.parameter.SqlParameterProcessor;

public class CurrentDateSqlParameterHandler extends SqlParameterProcessor {
	@Override
	public String getTitle() {
		return "当前日期参数";
	}

	@Override
	public String getDescription() {
		return this.getTitle() + " 赋当前日期";
	}

	@Override
	public List<String> getSqlParameterType() {
		return Arrays.asList(new String []{"CURRENT_DATE"});
	}

	@Override
	public void handle(StringBuilder sbSQL, Parameter parameter, List<SqlParameter> processors,SqlParameter sqlParameter) {
		sbSQL.append("?");
		processors.add(sqlParameter);
	}

	@Override
	public void setParameter(PreparedStatement ps, Parameter parameter, int index,SqlParameter sqlParameter) throws SQLException {
		java.sql.Date d = new java.sql.Date(new Date().getTime());
		ps.setDate(index, d);
	}

	@Override
	public String getUsage() {
		return "[CURRENT_DATE]";
	}
}
